#include <iostream>
#include <string.h>
#include "RootFindingMethod.h"
#include "DigitInputCheck.h"
using namespace std;
int z = 0;
int maxbound, minbound, settingchoice;
int methodchoice = 1;
int fxchoice= 1;
int intermediate = 0;
string check;
double guess, guess2, originalguess;
int iteration = 20;
float significant = 6;



int main()
{
    while (z!=7)
    {
    cout<<"Welcome to the Root Finder Program\n"<< endl;
    cout<<"Please Choose an Action Below by Typing the corresponding Number"<< endl;
    cout<<"The Default Use of this Program is to solve sin(x)-e^(-0.1x)\n"<<endl;
    cout<<"The output by default is accurate to 6 significant figures within 20 iterations\n\n"<< endl;
    cout<<"(1) Solve the Function According to Current Settings" << endl;
    cout<<"(2) Change the Current Settings" << endl;
    cout<<"(3) List the Points for Graphing " << endl;
    cout<<"(4) Exit the Program" << endl;
    cin >> check;
    if (IsNumeric(check) == true)
    {
        z = strtof(check.c_str(),NULL);
    }
    else
    {
        cout << "Please Try a Valid Input Next Time" << endl;
        pass();
        main();
    }
    switch(z)
    {
        case 1: // Solving
            if (fxchoice == 1)
            {
                if(methodchoice == 1)
                {
                    cout<<"Input the Guess for Newton-Raphson"<< endl;
                    cin >> originalguess;
                    NewtonMethod(F0,dF0,originalguess,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 2)
                {
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    SecantMethod(F0,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 3)
                {
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    BisectionMethod(F0,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 4)
                {
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    FalsePosition(F0,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 5)
                {
                    cout<<"Input the Guess for Newton-Raphson"<< endl;
                    cin >> originalguess;
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    NewtonMethod(F0,dF0,originalguess,significant, iteration, intermediate);
                    SecantMethod(F0,guess,guess2,significant, iteration, intermediate);
                    BisectionMethod(F0,guess,guess2,significant, iteration, intermediate);
                    FalsePosition(F0,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                }// closing if statement for function 1
                
                if (fxchoice == 2) // For Function 2
            {
                if(methodchoice == 1)
                {
                    cout<<"Input the Guess for Newton-Raphson"<< endl;
                    cin >> originalguess;
                    NewtonMethod(F1,dF1,originalguess,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 2)
                {
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    SecantMethod(F1,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 3)
                {
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    BisectionMethod(F1,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 4)
                {
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    FalsePosition(F1,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 5)
                {
                    cout<<"Input the Guess for Newton-Raphson"<< endl;
                    cin >> originalguess;
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    NewtonMethod(F1,dF1,originalguess,significant, iteration, intermediate);
                    SecantMethod(F1,guess,guess2,significant, iteration, intermediate);
                    BisectionMethod(F1,guess,guess2,significant, iteration, intermediate);
                    FalsePosition(F1,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                }// closing if statement for function 2
                
                
                 if (fxchoice == 3) // For Function 3
            {
                if(methodchoice == 1)
                {
                    cout<<"Input the Guess for Newton-Raphson"<< endl;
                    cin >> originalguess;
                    NewtonMethod(F2,dF2,originalguess,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 2)
                {
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    SecantMethod(F2,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 3)
                {
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    BisectionMethod(F2,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 4)
                {
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    FalsePosition(F2,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 5)
                {
                    cout<<"Input the Guess for Newton-Raphson"<< endl;
                    cin >> originalguess;
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    NewtonMethod(F2,dF2,originalguess,significant, iteration, intermediate);
                    SecantMethod(F2,guess,guess2,significant, iteration, intermediate);
                    BisectionMethod(F2,guess,guess2,significant, iteration, intermediate);
                    FalsePosition(F2,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                }// closing if statement for function 3
                
                
                if (fxchoice == 4) // For Function 4
            {
                if(methodchoice == 1)
                {
                    cout<<"Input the Guess for Newton-Raphson"<< endl;
                    cin >> originalguess;
                    NewtonMethod(F3,dF3,originalguess,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 2)
                {
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    SecantMethod(F3,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 3)
                {
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    BisectionMethod(F3,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 4)
                {
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    FalsePosition(F3,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 5)
                {
                    cout<<"Input the Guess for Newton-Raphson"<< endl;
                    cin >> originalguess;
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    NewtonMethod(F3,dF3,originalguess,significant, iteration, intermediate);
                    SecantMethod(F3,guess,guess2,significant, iteration, intermediate);
                    BisectionMethod(F3,guess,guess2,significant, iteration, intermediate);
                    FalsePosition(F3,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                }// closing if statement for function 4
                
                
                if (fxchoice == 5) // For Function 5
            {
                if(methodchoice == 1)
                {
                    cout<<"Input the Guess for Newton-Raphson"<< endl;
                    cin >> originalguess;
                    NewtonMethod(F4,dF4,originalguess,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 2)
                {
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    SecantMethod(F4,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 3)
                {
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    BisectionMethod(F4,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 4)
                {
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    FalsePosition(F4,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                if(methodchoice == 5)
                {
                    cout<<"Input the Guess for Newton-Raphson"<< endl;
                    cin >> originalguess;
                    cout<<"Input the Lower Bound Guess" << endl;
                    cin >> guess;
                    cout<<"Input the Upper Bound Guess" << endl;
                    cin >> guess2;
                    NewtonMethod(F4,dF4,originalguess,significant, iteration, intermediate);
                    SecantMethod(F4,guess,guess2,significant, iteration, intermediate);
                    BisectionMethod(F4,guess,guess2,significant, iteration, intermediate);
                    FalsePosition(F4,guess,guess2,significant, iteration, intermediate);
                    pass();
                    main();
                }
                }// closing if statement for function 5
                
                
            
            break;
        case 2: // Setting Page
            pass();
            SettingDeclare();
            cin >> settingchoice;
            
            switch(settingchoice)
            {
              case 1:   //Function to be solved
                Funchoice();
                cin >>fxchoice;
                pass();
                main();
                break;
              case 2: //Number of Significant Figure Accuracy
                    cout<< "Input Number of Significant Figures Accuracy" << endl;
                    cin >> significant;
                    pass();
                    main();
                    break;
              case 3: //Number of Iterations
                    cout <<"Input Number of Iterations "<< endl;
                    cin >> iteration;
                    pass();
                    main();
                    break;
             case 4: //Set the Root-Finding Method to be used
                    MethodChoice();
                    cin >> methodchoice;
                    pass();
                    main();
                    break;
             case 5: //Whether Intermediate Value is to be shown
                    cout << "[0] Don't Show the Intermediate Value "<< endl;
                    cout << "[1] Show the Intermediate Value " << endl;
                    cin >> intermediate;
                    pass();
                    main();
                    break;
            default:
            cout<< "Error, Input is not within the Specified Range!!" << endl;
            pass();
            main();
            break;   
            } // End of Setting Switch
            break;
        case 3: // Graphing Function
            pass();
            cout<<"Input the Lower Bound For Graphing" << endl;
            cin >> guess;
            cout<<"Input the Upper Bound For Graphing" << endl;
            cin >> guess2;
            cout <<"Input Number of Iterations In Between Bounds "<< endl;
            cin >> iteration;
            if(fxchoice == 1)
            {
                Graph(F0,guess,guess2,iteration);
            }
            if(fxchoice == 2)
            {
                Graph(F1,guess,guess2,iteration);
            }
            if(fxchoice == 3)
            {
                Graph(F2,guess,guess2,iteration);
            }
            if(fxchoice == 4)
            {
                Graph(F3,guess,guess2,iteration);
            }
            if(fxchoice == 5)
            {
                Graph(F4,guess,guess2,iteration);
            }
            
            pass();
            main();
            break;
        
        case 4: // Exiting Program
        cout<< "Exiting Program" << endl;
            return 0;
            break;
        default:
            cout<< "Error, Input is not within the Specified Range!!" << endl;
            pass();
            break;
            
            
            
        }//main switch close
    } 

}
            
    



